import { GeneraDataType } from "@/interface";
import { message, Modal } from "ant-design-vue";
import { createVNode } from "vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import { deleteLookupApi, disabledLookupApi, enabledLookupApi } from "@/api/configCenter/dataDictManagement";
// import { deketeMenuApi, editDictApi } from "@/api/systemSet/dataDictManagement";
export default function OperationHook(state: GeneraDataType) {
  const { dialogOpts, getData } = state;
  const editHandle = (row: GeneraDataType) => {
    console.log("编辑", row);
    dialogOpts.title = "编辑";
    dialogOpts.width = "740px";
    dialogOpts.type = 2;
    dialogOpts.component = "AddDataDict";
    dialogOpts.passData = row;
    dialogOpts.visible = true;
  };
  const addHandle = () => {
    dialogOpts.title = "新增";
    dialogOpts.width = "740px";
    dialogOpts.type = 1;
    dialogOpts.component = "AddDataDict";
    dialogOpts.visible = true;
  };
  const deleteHandle = (row: DataDictManagement.ListRows) => {
    Modal.confirm({
      title: "是否删除当前常量类型?",
      icon: createVNode(ExclamationCircleOutlined),
      content: "",
      okText: "确定",
      okType: "danger",
      cancelText: "取消",
      onOk() {
        deleteLookupApi({ id: row.id }).then((res: any) => {
          const { code } = res;
          if (code === 200) {
            message.success("删除成功!");
            getData();
          }
        });
      }
    });
  };
  const batchDeleteHandle = () => {
    Modal.confirm({
      title: "是否删除勾选的用户?",
      icon: createVNode(ExclamationCircleOutlined),
      content: "",
      okText: "确定",
      okType: "danger",
      cancelText: "取消",
      onOk() {
        console.log("OK");
      },
      onCancel() {
        console.log("Cancel");
      }
    });
  };
  // 修改状态
  const changeStatusHandle = (row: GeneraDataType) => {
    const params: any = {
      id: row.id
    };
    let tip = null,
      requestFn: any = null;
    if (row.status === 1) {
      tip = "是否停用该数据字典?";
      requestFn = disabledLookupApi;
    } else {
      tip = "是否启用该数据字典?";
      requestFn = enabledLookupApi;
    }
    Modal.confirm({
      title: tip,
      icon: createVNode(ExclamationCircleOutlined),
      content: "",
      okText: "确定",
      okType: "danger",
      cancelText: "取消",
      onOk() {
        requestFn(params).then((res: any) => {
          const { code } = res;
          if (code === 200) {
            message.success("操作成功!");
            getData();
          }
        });
      }
    });
  };
  return {
    editHandle,
    addHandle,
    deleteHandle,
    batchDeleteHandle,
    changeStatusHandle
  };
}
